﻿namespace Gonte
{
    /// <summary>
    /// Implementation of state holder
    /// </summary>
    public class StateHolder
        : IStateHolder
    {
        #region IStateHolder Members

        public IState State
        {
            get
            {
                return _state;
            }

            set
            {
                ExceptionThrower.ThrowWhenNull("State", value);

                if (null != _state)
                {
                    _state.OnExit(this); // Call the exit method of the previous state
                }

                _state = value; // Set the new state
                _state.OnEnter(this); // Call the enter method of the new state
            }
        }

        #endregion

        private IState _state;
    }
}
